<template>
  <div>
    <div v-if="list.length==0">暂无数据</div>
    <van-address-list
      v-model="chosenAddressId"
      :list="list"
      default-tag-text="默认"
      @add="onAdd"
      @edit="onEdit"
      @select="onSelect"
    />
  </div>
</template>

<script>
import { reqAddressList } from "../../http/api";
import { Toast } from "vant";
import log from '../../../../../../../../day06/资料/day06/代码/01homework/src/components/02-mixin/log';
export default {
  data() {
    return {
      //默认选中的id
      chosenAddressId: "1",
      list: [
        // {
        //   id: "1",
        //   name: "张三",
        //   tel: "13000000000",
        //   address: "浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室",
        //   isDefault: true,
        // },
      ],
    };
  },
  mounted() {
    //发请求
    reqAddressList({
      uid: JSON.parse(localStorage.getItem("user")).uid,
    }).then((res) => {
      var list = res.data.list ? res.data.list : [];
      this.list = list.map((item) => {
        return {
          id: item.id,
          name: item.username,
          tel: item.userphone,
          address: item.location + item.useraddress,
          isDefault: item.status === 1,
        };
      });
    });
  },
  methods: {
      //点添加按钮
    onAdd() {
      this.$router.push("/addressAdd");
    },
    //点编辑按钮
    onEdit(item, index) {
     this.$router.push("/addressAdd?id="+item.id)
    },
    //切换选中
    onSelect(item,index){
        this.$router.push("/order?addressId="+item.id)
    }
  },
};
</script>

<style>
</style>